package keeto.com.vn.bms.ui.adapter;

import java.util.ArrayList;

import keeto.com.vn.bms.model.BaseInfor.Education;
import keeto.com.vn.bms.ui.activity.R;
import keeto.com.vn.bms.utils.UniversalImageLoader;
import keeto.com.vn.bms.utils.Utils;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListEducationAdapter extends BaseAdapter {
	private ArrayList<Education> mList;
	private Context mContext;
	private LayoutInflater inflater;
	private UniversalImageLoader iLoader;

	public ListEducationAdapter(ArrayList<Education> mList, Context mContext) {
		super();
		this.mList = mList;
		this.mContext = mContext;
		this.iLoader = new UniversalImageLoader(mContext);
		this.inflater = LayoutInflater.from(mContext);

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_list_promotion, null);
			holder = new ViewHolder();
			holder.imgEducation = (ImageView) convertView
					.findViewById(R.id.img_item_promotion);
			holder.tvName = (TextView) convertView
					.findViewById(R.id.tv_name_item_promotion);
			holder.tvDesc = (TextView) convertView
					.findViewById(R.id.tv_des_item_promotion);
			holder.tvTime = (TextView) convertView
					.findViewById(R.id.tv_time_item_promotion);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.tvName.setText(mList.get(position).getTitle());
		holder.tvDesc.setText(mList.get(position).getIntro());
		if(!Utils.convertTimePromotion(mList.get(position).getDurationFrom()).equals("")){
			holder.tvTime.setText(mContext.getResources().getString(R.string.tv_time_education) + Utils.convertTimePromotion(mList.get(position).getDurationFrom()));
		}
		if(!mList.get(position).getImage().equals("")){

			iLoader.displayImageView(mList.get(position).getImage(), holder.imgEducation);

		}else{
			holder.imgEducation.setBackgroundResource(R.drawable.no_image);
		}

		return convertView;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	private class ViewHolder {
		TextView tvName;
		TextView tvDesc;
		TextView tvTime;
		ImageView imgEducation;
	}

}
